<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@page import="db.ReceiveorderDAO"%>
<%@page import="db.ReceivepurmatDAO"%>
<%@page import="db.ProjectDAO"%>
<%@page import="java.text.SimpleDateFormat"%>
<%@ include file="/jsp/common/utility/volti.jsp" %>
<%@ include file="/jsp/common/utility/logined.jsp"%>
<%
	WebApplicationContext ctx = WebApplicationContextUtils.getWebApplicationContext(getServletContext());
	ReceiveorderDAO receiveorderDao = (ReceiveorderDAO)ctx.getBean("ReceiveorderDAO");
	ReceivepurmatDAO receivepurmatDao = (ReceivepurmatDAO)ctx.getBean("ReceivepurmatDAO");
	ProjectDAO projectDao = (ProjectDAO)ctx.getBean("ProjectDAO");
	
	String searchSub = request.getParameter("searchSub");
	String searchType = request.getParameter("searchType");
	String searchKeyword = request.getParameter("searchKeyword");
	String pnStr = request.getParameter("pn");
	String lPrice = request.getParameter("lPrice");
	String gPrice = request.getParameter("gPrice");
	
	int pn = 0;
	int pageSize = 10;
	Integer teamId = (Integer)session.getAttribute("tid");
	
	int type = 1;
	
	if(pnStr != null && !"".equals(pnStr.trim())){
		try{
			pn = Integer.parseInt(pnStr);
		}catch(Exception e){
			pn = 0;
		}
	}
	
	List where = new ArrayList();
	
	where.add(new Object[]{"eq", "isDelete", 0});
	where.add(new Object[]{"eq", "teamId", teamId});
	where.add(new Object[]{"ne", "importNum", 0});
	where.add(new Object[]{"ne", "purNum", 0});
	
	if(searchSub != null && !"".equals(searchSub)){
		if(!"0".equals(searchSub))
			where.add(new Object[]{"eq", "subStore", Integer.parseInt(searchSub)});
	}
	
	if(lPrice != null && !"".equals(lPrice)){
		try{
			where.add(new Object[]{"ge", "purPrice", Float.parseFloat(lPrice)});
		}catch(Exception e){
			
		}
	}
	
	if(gPrice != null && !"".equals(gPrice)){
		try{
			where.add(new Object[]{"le", "purPrice", Float.parseFloat(gPrice)});
		}catch(Exception e){
			
		}
	}
	
	if(searchType != null && !"".equals(searchType)){
		if("1".equals(searchType))
			where.add(new Object[]{"like", "m.code", searchKeyword});
		else if("2".equals(searchType))
			where.add(new Object[]{"like", "m.name", searchKeyword});
		else if("3".equals(searchType))
			where.add(new Object[]{"like", "pr.code", searchKeyword});
	}
	
	Map map = receivepurmatDao.getReceivepurmat(pn, pageSize,
			new String[][]{new String[]{"desc","date"}},
			where,
			new String[][]{new String[]{"distinct","id"},new String[]{"","p.name"},new String[]{"","r.supplier"},new String[]{"","m.code"},new String[]{"","m.name"},new String[]{"","s.name"},new String[]{"","pr.code"},new String[]{"","batch"},new String[]{"","m.company"},new String[]{"","purPrice"},new String[]{"","importNum"},new String[]{"","useNum"},new String[]{"","r.remark"}}		
			,new String[]{"receiveorder","place","material","substore","project"});
	
	request.setAttribute("map",map);
	
	int pageTotal = ((Integer)map.get("pageTotal")).intValue();
	int pageNo = ((Integer)map.get("pageNo")).intValue();
	List pageList=getPage(pageTotal,pageNo);
	request.setAttribute("pages",pageList);

	request.setAttribute("lPrice",lPrice);
	request.setAttribute("gPrice",gPrice);
	request.setAttribute("searchSub",searchSub);
	request.setAttribute("searchType",searchType);
	request.setAttribute("searchKeyword",searchKeyword);
	
	pageContext.forward("/vm/search/seachStock.vm");
%>